package com.xydzxt.www.controller.student;

import com.xydzxt.www.model.Examinee;
import com.xydzxt.www.model.Major;
import com.xydzxt.www.model.Regist;
import com.xydzxt.www.service.ExamineeService;
import com.xydzxt.www.service.MajorService;
import com.xydzxt.www.service.RegistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class AdmissionController {
    @Autowired
    RegistService registService;
    @Autowired
    ExamineeService examineeService;
    @Autowired
    MajorService majorService;

    @GetMapping("/admissionQuery")
    public String admissionQuery(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        HttpSession session=req.getSession();
        if (session.getAttribute("sfzh")!=null){
            String idNumber=session.getAttribute("sfzh").toString();
            Regist regist=registService.selectByIdNumber(idNumber);
            Examinee examinee=examineeService.selectByRegistId(regist.getRegistId());
            if (examinee!=null){
                Major major=majorService.selectById(examinee.getAcceptMajorId());
                req.setAttribute("examinee",examinee);
                req.setAttribute("regist",regist);
                req.setAttribute("major",major);
                return "student/admissionQuery";
            }else {
                req.setAttribute("msg","请先进行报考缴费！考试出成绩后2个工作日内可查询录取结果！");
                return "student/msg";
            }
        }else {
            resp.sendRedirect("index");
        }
        return "";
    }
}


